<?php 
	session_start();
	
	include "connect.php";
	
	$no=$_GET['no'];	
	
	if($no==''){
		echo "Invalid Access";
		exit;
	}
	else{
		$query="SELECT * FROM post WHERE no=$no";
		$result=mysql_query($query) or die('Error: '.mysql_error());
		$row=mysql_fetch_array($result);	
		$check=mysql_num_rows($result);
		
		if(!$check){
			echo "
				<script>
					alert('There is no post for your request.');
					history.go(-1);
				</script>
			";
		}			
	}
	
	$query="UPDATE post SET hit=hit+1 WHERE no=$no";
	$result=mysql_query($query) or die('Error: '.mysql_error());
?>
<!DOCTYPE HTML/>
<html>
	<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
	<head>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
		<?php include "include.php"?>
	</head>
	<body onload="set_menu('qna');">
		<div class="container">
		<?php include "header.php";
					
			if($_SESSION['nick']==$row[writer]){
				echo '
					<div class="crimsonLink pull-right" style="position:relative;top:10px;">
						<a href="modify.php?no='.$no.'">Modify</a>
						<a href="delete.php?no='.$no.'">Delete</a><br/>
					</div>
				';
			}

			echo '
				<div>
					<header class="crimsonText">
						<h4><span class="lead"><i class="icon-asterisk"></i></span><a href="view.php?no='.$row[no].'"> '.$row[title].' </a></h4>
					</header>
					<p> '.$row[content].' </p>
				    <p></p>
				    <p class="crimsonLink">
					   	<i class="icon-user"></i><a href="#">'.$row[writer].'</a> 
				   		| <i class="icon-calendar"></i> '.$row[time].'
						| <i class="icon-heart"></i> '.$row[hit].'
				    </p>
					<hr/>
				</div>						
			';

			//comment
				$query="SELECT * FROM comment WHERE no=$no ORDER BY subno ASC";
				$result=mysql_query($query) or die('Error: '.mysql_error());
				$row=mysql_fetch_array($result);
				$check=mysql_num_rows($result);
				
				if($check != 0){
					echo '<ul class="media-list">';
					
					for($i=0; $i<$check; $i++){
						mysql_data_seek($result, $i);
						$row=mysql_fetch_array($result);
						
						echo '
							<li class="media">
								<div class="media-body crimsonLink">
									<span class="nick"><a href="#">'.$row[writer].'</a></span>	&nbsp;&nbsp; '.$row[time].'
									<span class="pull-right"><a href="#"><i class="icon-remove"></i></a> <a href="#"><i class="icon-edit"></i></a></span>
									<p>'.$row[content].'</p>			                  
								</div>
							</li>
						';
					}
					
					echo '</ul>';
				}
			?>
		
		    <form method="post" action="comment-db.php?no=<? echo $no;?>"> 
		       	<textarea class="textarea span12" name="content"></textarea>
		        <input type="submit" class="btn btn-inverse pull-right" value="Save"/>			                  			
		    </form>		
		
		<ul class="pager crimsonLink">
			<li class="previous"><a href="view.php?no=<?echo $no-1;?>"><i class="icon-chevron-left"></i> Prev</a></li>
			<li><a href="qna.php"><i class="icon-list"></i> List</a></li>
			<li class="next"><a href="view.php?no=<?echo $no+1;?>">Next <i class="icon-chevron-right"></i></a></li>	
		</ul>
		</div>
		<script src="js/menu.js"></script>
	</body>
</html>